<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="icms.ORM.Category" %>
<%@ page import="icms.service.CategoryService" %>
<%@ taglib uri="/WEB-INF/tlds/tree.tld" prefix="tree"%>
<%@ taglib uri="/struts-html" prefix="html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>categoryMan</title>
	<link rel="StyleSheet" href="css/dtree.css" type="text/css">
	<script type="text/javascript" src="js/dtree.js"></script>
	<tree:init />
</head>
  <body>
<table width="100%" height="100%" border="0">
<tr>
<td width="10%" height="100%" align="center" valign="top">
	<p />
	<tree:show />
</td>
<td valign="middle">
<% 
//获取栏目id
String idString=request.getParameter("id");
int id;
try{
	id=Integer.parseInt(idString);
}catch(Exception e){
	id=-1;
}
//实例化服务类对象
CategoryService service=new CategoryService();
//获取栏目的持久化对象
Category category=service.getCategoryByID(id);
if(category!=null){
%>
	<div align="center">
	<!-- 显示栏目信息   -->
<form action="categoryMan.do?method=categoryUpdate" method="post">
<table width="56%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
<tr bgcolor="#E7E7E7">
	<td height="24"  background="skin/images/tbg.gif">
		<input type="hidden" name="categoryID" value="<%= id %>" />栏目修改
	</td>
	<td align="right">
		<% if(category.getCategoryParentID()!=0){//二级栏目
				String url="href=\"deleteCategory.jsp?id="+id+"\"";
				out.write("<a onclick=\"return confirm('删除？')\""+url+">删除</a>"); 
				out.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
				out.write("<a href=\"#\">文章配置</a>");
			}else if(!service.hasChildCategories(category)){//没有子栏目
				String url="href=\"deleteCategory.jsp?id="+id+"\"";
				out.write("<a onclick=\"return confirm('删除？')\""+url+">删除</a>"); 
			}
		 %>
	</td>
</tr>
<tr height="32" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
	<td width="20%" align="right">父栏目：</td>
	<td width="80%" align="left">
		<select name="parentCategoryID" style="width:160px">
			<% //如果栏目本身是一级栏目，则不可跟换其父栏目
				if(category.getCategoryParentID()==0){
					out.write("<option value='0' selected='selected'>Root</option>");
				}else{
					List categoryList=new ArrayList();
					categoryList=service.getAllParentCategory();
					for(int i=0;i<categoryList.size();i++){
						Category thisCategory=(Category)categoryList.get(i);
						int value=thisCategory.getCategoryID();
						String text=thisCategory.getCategoryName();
						if((thisCategory.getCategoryID()).equals(category.getCategoryParentID())){
							out.write("<option value='"+value+"' selected='selected'>"+text+"</option>");
						}else{
							out.write("<option value='"+value+"'>"+text+"</option>");
						}
					}
				}
			 %>
		</select>
	</td>
</tr>
<tr height="32" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
	<td width="20%" align="right">名  称：</td>
	<td width="80%" align="left">
		<input type="text" name="categoryName" style="width:160px" maxlength="20" value="<%= category.getCategoryName() %>" />
		<%
			String nameMsg=(String)session.getAttribute("nameError");
			if(nameMsg!=null&&(!nameMsg.equals(""))){
				out.write("<font color='red'>"+nameMsg+"</font>");
				session.setAttribute("nameError",null);
			}
		%>
	</td>
</tr>
<tr height="32" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
	<td  align="right">序  号：</td>
	<td  align="left">
		<input type="text" name="categorySequence" style="width:40px" maxlength="3" value="<%= category.getCategorySequence() %>" />
		<%
			String sequenceMsg=(String)session.getAttribute("sequenceError");
			if(sequenceMsg!=null&&(!sequenceMsg.equals(""))){
				out.write("<font color='red'>"+sequenceMsg+"</font>");
				session.setAttribute("sequenceError",null);
			}
		%>
	</td>

</tr>
<tr height="32" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
	<td  align="right">状  态：</td>
	<td  align="left">
		<select name="categoryDisplay" style="width:80px">
			<% 
				//如果栏目是二级栏目，且其父栏目是关闭状态，则不可开启此二级栏目 flag=1;
				int flag=0;
				//父栏目id
				int parentCategoryID=category.getCategoryParentID();
				if(parentCategoryID!=0){//不是一级栏目 
					//获取其父栏目
					Category parentCategory=service.getCategoryByID(category.getCategoryParentID());
					int parentCategoryDisplay=parentCategory.getCategoryDisplay();
					if(parentCategoryDisplay==0){//不是一级栏目 &&父栏目关闭
						out.write("<option value='0' selected='selected'>关闭</option>");
						flag=1;
					}
				}
				if(flag==0){
					if(category.getCategoryDisplay()==1){
						out.write("<option value='1' selected='selected'>开启</option>");
						out.write("<option value='0'>关闭</option>");
					}else{
						out.write("<option value='0' selected='selected'>关闭</option>");
						out.write("<option value='1'>开启</option>");
					}
				}
			 %>
			
			
		</select>

	</td>
</tr>
<tr height="80" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
	<td  align="right" valign="top">介  绍：</td>
	<td  align="left" valign="top">
		<textarea name="categoryIntroduce" style="width:280px; height:60px;"><%= category.getCategoryIntroduce() %></textarea>
	</td>
</tr>
<tr height="20" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
	<td  align="center" colspan="2">
		<input type="submit" value="保  存"  />&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="reset" value="取  消"  />
	</td>
</tr>
<tr height="20">
	<td  align="center" colspan="2">
		<%
			String news=(String)session.getAttribute("updateCategoryNews");
			if(news!=null && (!news.equals("")) ){
				out.write("<font color='red'>"+news+"</font>");
			}
			session.setAttribute("updateCategoryNews",null);
		 %>
		&nbsp;
	</td>
</tr>
</table>
</div>
</form>
<%
		}
%>
&nbsp;
</td>
</tr>
</table>
  </body>
</html>
